package com.jiang.longin_demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.jiang.longin_demo.entity.User;
import com.jiang.longin_demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController

public class UserController {
    @GetMapping
    public String index() {
        return "Hello World";
    }
    @Autowired
    private UserService userService;
    @GetMapping("list")
    public List<User> list() {
       return userService.listAll();
    }
//    数据的添加操作
    @PostMapping("/save")
    public boolean save(@RequestBody User user) {
        return userService.save(user);
    }
//    数据的修改操作
    @PostMapping("/mod")
    public boolean mod(@RequestBody User user) {
        return userService.updateById(user);
    }
//    新增或修改的方法 saveOrMod
    @PostMapping("/saveOrMod")
    public boolean saveOrMod(@RequestBody User user) {
        return userService.saveOrUpdate(user);
    }
//    删除语句
    @GetMapping("/delete")
    public boolean delete(Integer id) {
        return userService.removeById(id);
    }
//    模糊查询
//    @PostMapping("/listAll")
//    public List<User> listAll(@RequestBody User user) {
//        LambdaQueryWrapper<User> lambdaQueryWrapper=new LambdaQueryWrapper();
//        LambdaQueryWrapper.eq(User::getName,user.getName());
//        return userService.listAll(lambdaQueryWrapper);
//
//    }





}
